#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Copyright (c) 2025 粤港澳大湾区（广东）国创中心

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.

File: CAD.py
Desc: CAD view widget for displaying the CAD model.
Author: xumanjia
Date: 2025-08-01
"""
from PyQt5.QtWidgets import QLabel
from PyQt5.QtCore import Qt,QEvent

class cadView(QLabel):
    def __init__(self, text, parent=None):
        super().__init__(text, parent)
        self.doc = self.parent().doc
        self.NCTI = self.parent().NCTI
    
    def resizeEvent(self, event):
        self.update()      
        if False == hasattr(self, 'doc') :
            return
        if self.doc.ID == -1:
            return
        if False == hasattr(self, 'view') :
            return
        pos = self.pos()
        xPos = 10
        yPos = 50
        view = self.view
        view.SetGeometry(pos.x() - xPos, pos.y() - yPos, self.width() + xPos, self.height() + yPos)
        self.doc.Update()
        
    def updateDoc(self, parent = None):
        if parent != None:
            if hasattr(parent, 'doc') :
                self.doc = parent.doc
            if hasattr(parent, 'NCTI') :
                self.NCTI = parent.NCTI
            if hasattr(parent, 'view') :
                self.view = parent.view